#include "head.h"

int do_mkdir(client_status_t *status){

    self_defined_pro_t *server_message=(self_defined_pro_t *)calloc(1,sizeof(self_defined_pro_t));
    self_defined_pro_t *mes=(self_defined_pro_t *)calloc(1,sizeof(self_defined_pro_t));
    server_message->cmd=create_dir;
    server_message->para_num=1;

    //当前命令初始化到网络结构体
    char *para=strtok(status->runtime_cmd," ");
    para=strtok(NULL," ");

    strcpy(server_message->message,"username=");
    strcat(server_message->message,status->user);
    strcat(server_message->message,"&");
    strcat(server_message->message,"path=");
    strcat(server_message->message,status->path);
    strcat(server_message->message,"&");
    strcat(server_message->message,"dir=");
    strcat(server_message->message,para);

    send(status->socket_fd,server_message,sizeof(self_defined_pro_t),MSG_NOSIGNAL);
    recv(status->socket_fd,mes,sizeof(self_defined_pro_t),MSG_WAITALL);

    char result[60]={0};
    if(mes->cmd==200){
        strcpy(result,mes->message);
        char *res=strtok(result,"=");
        res=strtok(NULL,"=");
        printf("%s\n",res);
        return 1;
    }
    strcpy(result,mes->message);
    char *res=strtok(result,"=");
    res=strtok(NULL," ");
    return 0;
}



int create_directory(client_status_t *status){
    printf("create_directory 1\n");

    self_defined_pro_t *server_message=(self_defined_pro_t *)calloc(1,sizeof(self_defined_pro_t));
    self_defined_pro_t *mes=(self_defined_pro_t *)calloc(1,sizeof(self_defined_pro_t));
    server_message->cmd=create_dir;
    server_message->para_num=1;

    //当前命令初始化到网络结构体
    char *para=strtok(status->runtime_cmd," ");
    para=strtok(NULL," ");
    strcpy(server_message->message,para);
    server_message->message_len=strlen(server_message->message);

    // TODO: 需要发送: 用户名, 当前路径, 创建的目录
    send(status->socket_fd,server_message,sizeof(self_defined_pro_t),MSG_NOSIGNAL);



    recv(status->socket_fd,mes,sizeof(self_defined_pro_t),MSG_WAITALL);

    printf("create_directory16 \n");
    char result[60]={0};
    if(mes->cmd==-1){
        strcpy(result,mes->message);
        char *res=strtok(result,"&");
        res=strtok(NULL,"=");
        res=strtok(NULL," ");
        printf("%s\n",res);
        return 1;
    }
    printf("create_directory26 \n");
    strcpy(result,mes->message);
    strtok(result,"=");
    printf("create_directory29 \n");
    char *res=strtok(NULL," ");
    printf("create_directory31 \n");
    //printf("%s\n",res);
    return 0;
}

